package com.muyu.product.controller;

import com.muyu.common.core.domain.R;
import com.muyu.product.domain.pojo.ProductInfoPO;
import com.muyu.product.domain.req.ProductInfoReq;
import com.muyu.product.domain.req.ProductSkuReq;
import com.muyu.product.domain.vo.ProductInfoVo;
import com.muyu.product.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName ProductController
 * @Description 描述
 * @Author ShiYu.Cui
 * @Date 2024/3/26 20:30
 */
@RestController
@RequestMapping("product/info")
@Api(tags = "商品管理")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 添加商品信息
     * @param productInfoReq
     * @return
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation("添加商品信息")
    public R<ProductInfoReq> saveOrUpdate(@RequestBody ProductInfoReq productInfoReq){
        productService.saveOrUpdate(productInfoReq);
        return R.ok();
    }

    /**
     * 商品信息列表
     * @param productInfoVo
     * @return
     */
    @PostMapping("/productList")
    @ApiOperation("查询商品信息")
    public R<List<ProductInfoPO>> productList(@RequestBody ProductInfoVo productInfoVo){
        return productService.productList(productInfoVo);
    }

    @GetMapping("/getProductDetailById")
    @ApiOperation("根据ID获取商品详情")
    public R<ProductInfoReq> getProductDetailById(@RequestParam Integer id){
        ProductInfoReq productInfoReq= productService.getProductDetailById(id);
        return R.ok(productInfoReq);
    }

}
